*************************************************************
*** Standardize

* Lowercase and get replace ä etc.
foreach var in  Strasse {
	replace `var' = lower(`var')
	replace `var' = subinstr(`var', "ä", "ae", .)
	replace `var' = subinstr(`var', "ö", "oe", .)
	replace `var' = subinstr(`var', "ü", "ue", .)
	replace `var' = subinstr(`var', "ê", "e", .)
	replace `var' = subinstr(`var', "é", "e", .)
	replace `var' = subinstr(`var', "è", "e", .)
	replace `var' = subinstr(`var', "ì", "i", .)
	replace `var' = subinstr(`var', "í", "i", .)
	replace `var' = subinstr(`var', "î", "i", .)
	replace `var' = subinstr(`var', "ô", "o", .)
	replace `var' = subinstr(`var', "ç", "c", .)
	replace `var' = trim(`var')
}

* Lowercase HausNr
replace HausNr = lower(HausNr)
replace HausNr=subinstr(HausNr, "GVB","",.)


* Some Households have several names
replace HausNr=subinstr(HausNr, "/","@",.)
replace HausNr=subinstr(HausNr, "+","@",.)
replace HausNr=subinstr(HausNr, "-","@",.)

/*
foreach var in HausNr {
	split `var', p("@")
	preserve
		drop `var'
		rename `var'2 `var'
		drop `var'?
		drop if `var'==""
		tempfile part2
		save `part2',replace
	restore
	drop `var' 
	rename `var'1 `var'
	drop `var'?
	append using `part2'
}
*/

* Create HausNr wihout letter
gen HausNr_withletter = HausNr

foreach buch in a b c d e f g h i j k l m n o p q r s t u v w x y z {
	qui replace HausNr=subinstr(HausNr, "`buch'","",.)
}


* Get rid of empty spaces
replace HausNr=trim(HausNr)
replace HausNr_withletter = trim(HausNr_withletter)


* Combined Variable for easier merge
tostring PLZ, replace force
gen Adress = Strasse+" "+HausNr+" "+PLZ
gen Adress_withletter = Strasse+" "+HausNr_withletter+" "+PLZ
drop Strasse HausNr PLZ HausNr_withletter

replace Adress = trim(Adress)
replace Adress_withletter = trim(Adress_withletter)
